package org.elzat.healthboxgatewayapp.credentials;

import com.google.common.collect.Sets;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;

import java.util.Set;

import static org.elzat.healthboxgatewayapp.credentials.HealthBoxAuthority.*;

public enum HealthBoxUserRole {

    USER(Sets.newHashSet(
            APPOINTMENT_READ, APPOINTMENT_MAKE,
            NOTIFICATION_READ, NOTIFICATION_UPDATE,
            HEALTH_READ, HEALTH_WRITE, REPORT_READ, REPORT_WRITE,
            ORGAN_READ,
            RESULT_READ
    )),

    ORGAN_ADMIN(Sets.newHashSet(
            APPOINTMENT_READ, APPOINTMENT_MAKE, APPOINTMENT_CREATE,
            NOTIFICATION_READ, NOTIFICATION_WRITE,
            USER_READ, ORGAN_READ, RISK_READ, RISK_WRITE,
            RESULT_READ
    )),

    SYSTEM_ADMIN(Sets.newHashSet(
            USER_READ, USER_WRITE,
            APPOINTMENT_READ, APPOINTMENT_MAKE, APPOINTMENT_CREATE,
            NOTIFICATION_READ, NOTIFICATION_WRITE, NOTIFICATION_UPDATE,
            ORGAN_READ, ORGAN_WRITE,
            RESULT_READ, RESULT_WRITE
    ));

    private final Set<GrantedAuthority> authorities;

    HealthBoxUserRole(Set<GrantedAuthority> authorities) {
        this.authorities = authorities;
    }

    public Set<GrantedAuthority> getAuthorities() {
        authorities.add(HealthBoxAuthority.get(this));
        return authorities;
    }
}
